package cc.yugu.yhdw.webserver.web.controller.security.hdw;

import cc.yugu.yhdw.common.annotation.ViewModel;
import cc.yugu.yhdw.common.domain.hdw.UnregisterBatteryReportLog;
import cc.yugu.yhdw.common.entity.json.PageResult;
import cc.yugu.yhdw.webserver.constant.AppConstEnum;
import cc.yugu.yhdw.webserver.service.hdw.UnregisterBatteryReportLogService;
import cc.yugu.yhdw.webserver.web.controller.security.SecurityController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping(value = "/security/hdw/unregister_battery_report_log")
public class UnregisterBatteryReportLogController extends SecurityController {
    @Autowired
    UnregisterBatteryReportLogService unregisterBatteryReportLogService;

    @RequestMapping(value = "index.htm")
    public void index(Model model) {
        model.addAttribute(MENU_CODE_NAME, AppConstEnum.Menu.MENU_03_09.getValue());
    }

    @RequestMapping("page.htm")
    @ViewModel(ViewModel.JSON)
    @ResponseBody
    public PageResult page(UnregisterBatteryReportLog search) {
        return PageResult.successResult(unregisterBatteryReportLogService.findPage(search));
    }

    @RequestMapping(value = "view.htm")
    public String view(Model model, String code, Date createTime) {
        UnregisterBatteryReportLog entity = unregisterBatteryReportLogService.find(code, createTime);
        if(entity == null) {
            return SEGMENT_RECORD_NOT_FOUND;
        } else {
            model.addAttribute("entity", entity);
        }
        return "/security/hdw/unregister_battery_report_log/view";
    }

}
